﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MefTZAddin.interop.types;
using System.Runtime.InteropServices;

namespace MefTZAddin.interop
{
    public static class RegistryTimeZoneInformationInterop
    {
        public static REG_TZI_FORMAT GetRegTziFormat(byte[] tziRegValue)
        {
            REG_TZI_FORMAT rtzi;

            object varValue = tziRegValue;
            byte[] baData = varValue as byte[];
            int iSize = baData.Length;
            IntPtr buffer = Marshal.AllocHGlobal(iSize);
            Marshal.Copy(baData, 0, buffer, iSize);
            rtzi = (REG_TZI_FORMAT)Marshal.PtrToStructure(buffer, typeof(REG_TZI_FORMAT));
            Marshal.FreeHGlobal(buffer);

            return rtzi;
        }
    }
}
